#include "clientconnectionlist.h"

bool ClientConnectionList::AddClient(ClientConnection client)
{
	m_client_list.push_back(client);
	return true;
}

bool ClientConnectionList::GetClient(unsigned number, ClientConnection& client)
{
	if (number < m_client_list.size())
	{
		client = m_client_list.at(number);
		return true;
	}

	return false;
}

bool ClientConnectionList::GetClient(std::string guid, ClientConnection*& client)
{
	// Iterate through all and compare.
	for (std::vector<ClientConnection>::iterator it = m_client_list.begin(); it != m_client_list.end(); it++)
	{
		if (it->guid() == guid)
		{
			client = &(*it);
			return true;
		}
	}

	return false;
}

bool ClientConnectionList::RemoveClient(unsigned number)
{
	if (number < m_client_list.size())
	{
		m_client_list.erase(m_client_list.begin() + number);
		return true;
	}

	return false;
}

bool ClientConnectionList::RemoveClient(std::string guid)
{
	// Iterate through all and compare.
	for (std::vector<ClientConnection>::iterator it = m_client_list.begin(); it != m_client_list.end(); it++)
	{
		if (it->guid() == guid)
		{
			m_client_list.erase(it);
			return true;
		}
	}

	return false;
}

bool ClientConnectionList::RemoveClient(std::string guid, unsigned& number)
{
	// Iterate through all and compare.
	for (std::vector<ClientConnection>::iterator it = m_client_list.begin(); it != m_client_list.end(); it++)
	{
		if (it->guid() == guid)
		{
			// The index of the element.
			number = it - m_client_list.begin();

			m_client_list.erase(it);
			return true;
		}
	}

	return false;
}

unsigned ClientConnectionList::GetSize()
{
	return m_client_list.size();
}